/**
 * 商品API接口
 */
import api from './chat'

export interface ProductSearchResponse {
  success: boolean
  products: any[]
  total: number
  keyword: string
}

export interface CouponsResponse {
  success: boolean
  coupons: any[]
  total: number
}

export interface PriceHistoryItem {
  date: string
  price: number
  original_price?: number
  reason?: string
}

export interface PriceStatistics {
  highest_price: number
  lowest_price: number
  average_price: number
  price_trend: 'up' | 'down' | 'stable'
  change_rate: number
  is_lowest_recently: boolean
}

export interface PriceHistoryResponse {
  success: boolean
  product_id: number
  product_sn: string
  product_name: string
  days: number
  current_price: number
  statistics: PriceStatistics
  history: PriceHistoryItem[]
  total: number
}

/**
 * 搜索商品
 */
export const searchProducts = (params: {
  keyword: string
  category?: string
  limit?: number
}): Promise<ProductSearchResponse> => {
  return api.get('/products/search', { params })
}

/**
 * 获取用户优惠券
 */
export const getCoupons = (userId: number): Promise<CouponsResponse> => {
  return api.get(`/products/coupons/${userId}`)
}

/**
 * 获取商品价格历史
 */
export const getPriceHistory = (params: {
  product_id?: number
  product_sn?: string
  days?: number
}): Promise<PriceHistoryResponse> => {
  return api.get('/products/price-history', { params })
}

